<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('检测列表')"/>
    <link rel="stylesheet" th:href="@{/msg-layer/naranja.min.css}">
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="btn-group-sm" id="toolbar-precheck" role="group">
            <h3 class="inline">待检测：</h3>
        </div>
        <div class="col-sm-12 select-table table-striped ">
            <table id="bootstrap-table-1" data-mobile-responsive="true"></table>
        </div>

        <div class="btn-group-sm" id="toolbar1" role="group">
            <h3 class="inline">检测信息：</h3>
            <a class="btn btn-primary" onclick="openOrder()">
                <i class="fa fa-table"></i> 检测记录单
            </a>


            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 确认
            </a>
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncCheck:add">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
    <div class="bottom-btns"></div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/webjars/sockjs-client/1.0.2/sockjs.min.js}"></script>
<script th:src="@{/webjars/stomp-websocket/2.3.3/stomp.min.js}"></script>
<script th:src="@{/msg-layer/naranja.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncCheck:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncCheck:remove')}]];
    var guaqi = [[${@permission.hasPermi('system:ncCheck:guaqi')}]];
    var prefix = ctx + "system/ncCheck";
    var datas = [[${@dict.getType('check_result')}]];
    $(function () {
        var options1 = {
            url: prefix + "/list?status=3",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "检测",
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            pageSize: 7,
            toolbar: 'toolbar1',
            columns: [{
                title: '序号',
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'checkId',
                    title: '检测id',
                    visible: false
                }, {
                    field: 'ncorderCf.cforderCode',
                    title: '订单编号',
                    formatter: function (value, row, index) {
                        if (row.ncorderCf.isCheck == '1') {
                            return '--'
                        } else {
                            return row.ncorderCf.cforderCode
                        }

                    }

                },
                {
                    field: 'piciCode',
                    title: '蔬菜批次',
                    sortable: true
                }, {
                    field: 'ncorderCf.cropNameCn',
                    title: '作物名称',
                },
                {
                    field: 'ncorderCf.cropVarietiesCn',
                    title: '作物品种',
                },
                {
                    field: 'teamCn',
                    title: '生产班组',

                },

                {
                    field: 'yzl',
                    title: '抑制率(%)',
                    sortable: true
                },
                {
                    field: 'checkResult',
                    title: '检测结果',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'checkTime',
                    title: '检测时间',
                    sortable: true
                },
                {
                    field: 'checkUser',
                    title: '检测人员',
                    sortable: true
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.checkId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.checkId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };

        initPreCheck();
        $.table.init(options1);
        var btns = [{
            name: '工作记录',
            url: ctx + 'system/ncNormalWorks?workType=6',
            id: 'normal-work'
        }]
        addBtns(btns);


    });

    /*初始化待检测列表*/
    function initPreCheck() {
        var prefix = ctx + "system/ncOrderCf";
        var datas = [[${@dict.getType('cforderType')}]];
        var cforderStatus = [[${@dict.getType('cforderStatus')}]];
        var normal_unit = [[${@dict.getType('normal_unit')}]];

        var options = {
            url: prefix + "/list?cforderStatus=2",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "菜房订单",
            pageSize: 7,
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            id: 'bootstrap-table-1',
            toolbar: 'toolbar-precheck',
            columns: [
                {
                    field: 'cforderId',
                    title: '主键',
                    visible: false
                },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                }, {
                    field: 'cforderCode',
                    title: '订单编号',
                    sortable: true
                },
                {
                    field: 'cropNameCn',
                    title: '检测内容',
                    formatter: function (value, row, index) {
                        return row.cropNameCn + "--" + row.cropVarietiesCn + "--" + row.requestAmount + "(" + $.table.selectDictLabel(normal_unit, row.unit) + ")";
                    }
                },
                {
                    field: 'requestTime',
                    title: '需求日期',
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    }
                },
                {
                    field: 'cforderType',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'cforderStatus',
                    title: '状态',
                    sortable: false,
                    formatter: function (value, row, index) {
                        /*蔬菜类状态：1、待分配，2、待检测，3、待入库，4、待出库，5、已完成
                        牛奶鸡蛋：6、牛舍待确认，7、鸡舍待确认，8、牛舍已确认，9、鸡舍已确认*/
                        return $.table.selectDictLabel(cforderStatus, value);
                    }
                },
                {
                    field: 'distribution',
                    title: '分配情况',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if (1 == value) {
                            return "检测"
                        }
                        if (2 == value) {
                            return "仓储"
                        }
                        return "--";
                    }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        actions.push('<a class="btn btn-danger btn-xs ' + guaqi + '" href="javascript:void(0)" onclick="guaQi(\'' + row.cforderId + '\')"><i class="fa fa-remove"></i>挂起</a> ');
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="confirmCheck(\'' + row.cforderId + '\')"><i class="fa fa-send"></i>确认</a>');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        /*状态:1：待确认 2：已挂起 3：已确认：4：已生成订单*/
    }

    /*确认检测 单条*/
    function confirmCheck(id) {
        var url = prefix + "/confirmCheck/" + id;
        $.modal.open("检测录入", url);
    }

    /*确认检测 单条*/
    function guaQi(id) {
        var url = prefix + "/guaQi";
        $.modal.confirm("确认挂起吗？", function () {
            myPost(url, {cforderId: id},
                function (data) {

                    if (data.code == 0) {
                        $.modal.msgSuccess();
                    } else {
                        $.modal.msgWarning(data.msg);
                    }
                    reload()
                }, function (e) {
                    $.modal.msgError();
                    reload()
                })
        });
    }

    /*表单确认*/
    function confirmTable() {
        var confirmTable = prefix + "/confirmTable";
        var data = $('#bootstrap-table').bootstrapTable('getData');
        if (data && data.length > 0) {

            $.modal.confirm("确认生成检测单吗？", function () {
                var ids = [];
                $(data).each(function (i, e) {
                    ids.push(e.checkId);
                });
                var ids_str = ids.join(",");
                myPost(confirmTable, {ids: ids_str},
                    function (data) {

                        if (data.code == 0) {
                            layer.msg("提交成功")
                        } else {
                            layer.msg(data.msg);
                        }
                        reload()
                    }, function (e) {
                        layer.msg("确认失败!");
                        reload()
                    })

            })
        } else {
            layer.msg("未发现数据!")
        }

    }

    /*打开检测记录单*/
    function openOrder() {
        var url = ctx + 'system/ncOrder?orderType=4';
        $.modal.openTab("检测记录单", url);
    }

    function reload() {
        $('#bootstrap-table').bootstrapTable('refresh', {
            silent: true
        });
        $('#bootstrap-table-1').bootstrapTable('refresh', {
            silent: true
        });
    }
    setTitle("检测管理",false)

</script>
</body>
</html>